﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Neits.UserService;
using Projecturo.Model;
using Neits.Common;

namespace Projecturo.Connectivity
{
    public class Authentication : IAuthentication
    {
        [Dependency]
        public IUserService UserService
        {
            get;
            set;
        }

        #region IAuthentication Member

        public IUser Login(LoginInformation loginInformation, IDataContext context)
        {
            if (loginInformation == null)
                throw new ArgumentNullException("loginInformation");

            User user = new User { Username = loginInformation.Username, Password = loginInformation.Password };

            IUser loggedInUser = UserService.LoginUser(user, context);

            if (loggedInUser != null)
                return loggedInUser;
            return null;
        }

        #endregion
    }
}
